﻿// ImageCaptureDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "ImageCaptureDlg.h"
#include "afxdialogex.h"


// CImageCaptureDlg 对话框

IMPLEMENT_DYNAMIC(CImageCaptureDlg, CDialogEx)

CImageCaptureDlg::CImageCaptureDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_CAPTURE, pParent)
	, m_bWriteiic(FALSE)
	, m_bMirrorX(FALSE)
	, m_bMirrorY(FALSE)
	, m_nCTSId(0)
	, m_dFeildRatio(0)
	, m_nGpioFlag(FALSE)
	, m_bChangeXY(FALSE)
	, FW_SlaveAdd(_T(""))
	, IICFlag(FALSE)
	, m_bMirrorXt(FALSE)
	, m_bMirrorYt(FALSE)
	, SNAddr(_T(""))
	, IMAGE_W(0)
	, IMAGE_H(0)
	, MesIP(_T(""))
	, MesPort(0)
	, wpCode(_T(""))
	, gdNo(_T(""))
	, isOpenMes(FALSE)
{

}

CImageCaptureDlg::~CImageCaptureDlg()
{
}

void CImageCaptureDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_IMAGE_CENTER_LINE_TYPE, m_comboCenterLineType);
	DDX_Control(pDX, IDC_IMAGE_FIELD_LINE_TYPE, m_comboFeildLineType);
	DDX_Control(pDX, IDC_IMAGE_CENTER_LINE_COLOR, m_comboCenterLineColor);
	DDX_Control(pDX, IDC_IMAGE_FIELD_LINE_COLOR, m_comboFeildLineColor);

	DDX_Control(pDX, IDC_COMBO_IMAGE_SOURCE, m_comboImageSource);
	DDX_Control(pDX, IDC_COMBO_TEST_MODE, m_comboTestMode);
	DDX_Control(pDX, IDC_COMBO_CAPTURE_MODE, m_comboCaptureMode);
	DDX_Control(pDX, IDC_COMBO_CHANGE_MODE, m_comboChangeMode);
	DDX_Check(pDX, IDC_CHECK_WRITE_IIC, m_bWriteiic);
	DDX_Check(pDX, IDC_CHECK_MIRROR_X, m_bMirrorX);
	DDX_Check(pDX, IDC_CHECK_MIRROR_Y, m_bMirrorY);
	DDX_Text(pDX, IDC_EDIT_CTS_ID, m_nCTSId);
	DDX_Text(pDX, IDC_IMAGE_CENTER_LINE_WIDTH, m_nCenterWide);
	DDX_Text(pDX, IDC_IMAGE_FIELD_LINE_WIDTH, m_nFeildWide);
	DDX_Text(pDX, IDC_IMAGE_FIELD_LINE_LOCATION, m_dFeildRatio);
	DDX_Check(pDX, IDC_CHECK_GPIO, m_nGpioFlag);
	DDX_Control(pDX, IDC_COMBO_GPIO, m_comboGpioNo);
	DDX_Check(pDX, IDC_CHECK_CHANGEXY, m_bChangeXY);
	DDX_Text(pDX, IDC_EDIT1, FW_SlaveAdd);
	DDX_Check(pDX, IDC_CHECK4, IICFlag);
	DDX_Check(pDX, IDC_CHECK_MIRROR_Xt, m_bMirrorXt);
	DDX_Check(pDX, IDC_CHECK_MIRROR_Yt, m_bMirrorYt);
	DDX_Text(pDX, IDC_EDIT8, SNAddr);
	DDX_Text(pDX, IDC_IMAGE_W, IMAGE_W);
	DDX_Text(pDX, IDC_IMAGE_H, IMAGE_H);
	DDX_Text(pDX, IDC_EDIT131, MesIP);
	DDX_Text(pDX, IDC_EDIT171, MesPort);
	DDX_Text(pDX, IDC_EDIT111, wpCode);
	DDX_Text(pDX, IDC_EDIT121, gdNo);
	DDX_Check(pDX, IDC_CHECK_IS_OPENMES, isOpenMes);
}


BEGIN_MESSAGE_MAP(CImageCaptureDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CImageCaptureDlg::OnBnClickedButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_WRITEIIC, &CImageCaptureDlg::OnBnClickedButtonWriteiic)
	ON_BN_CLICKED(IDC_BUTTON_READIIC, &CImageCaptureDlg::OnBnClickedButtonReadiic)
	ON_BN_CLICKED(IDC_BUTTON_SAVE2, &CImageCaptureDlg::OnBnClickedButtonSave2)
	ON_BN_CLICKED(IDC_BUTTON_CHECKGD, &CImageCaptureDlg::OnBnClickedButtonCheckgd)
END_MESSAGE_MAP()


// CImageCaptureDlg 消息处理程序


BOOL CImageCaptureDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	ReadConfigIni();

	m_comboCenterLineType.ResetContent();
	m_comboCenterLineType.AddString(L"0: Solid");
	m_comboCenterLineType.AddString(L"1: Dash");
	m_comboCenterLineType.AddString(L"2: Dot");
	m_comboCenterLineType.AddString(L"3: DashDot");
	m_comboCenterLineType.AddString(L"4: DashDotDot");
	m_comboCenterLineType.SetCurSel(gSystemMgr.m_nCenterLineType);

	m_comboFeildLineType.ResetContent();
	m_comboFeildLineType.AddString(L"0: Solid");
	m_comboFeildLineType.AddString(L"1: Dash");
	m_comboFeildLineType.AddString(L"2: Dot");
	m_comboFeildLineType.AddString(L"3: DashDot");
	m_comboFeildLineType.AddString(L"4: DashDotDot");
	m_comboFeildLineType.SetCurSel(gSystemMgr.m_nFeildLineType);

	m_comboCenterLineColor.ResetContent();
	m_comboCenterLineColor.AddString(L"0: Red");
	m_comboCenterLineColor.AddString(L"1: Green");
	m_comboCenterLineColor.AddString(L"2: Blue");
	m_comboCenterLineColor.AddString(L"3: Yellow");
	m_comboCenterLineColor.AddString(L"4: YellowGreen");
	m_comboCenterLineColor.SetCurSel(gSystemMgr.m_nCenterLineColor);

	m_comboFeildLineColor.ResetContent();
	m_comboFeildLineColor.AddString(L"0: Red");
	m_comboFeildLineColor.AddString(L"1: Green");
	m_comboFeildLineColor.AddString(L"2: Blue");
	m_comboFeildLineColor.AddString(L"3: Yellow");
	m_comboFeildLineColor.AddString(L"4: YellowGreen");
	m_comboFeildLineColor.SetCurSel(gSystemMgr.m_nFeildLineColor);

	m_comboImageSource.ResetContent();
	m_comboImageSource.AddString(L"0: 本地文件");
	m_comboImageSource.AddString(L"1: CTS采集卡");
	m_comboImageSource.AddString(L"2: 软龙格采集卡");
	m_comboImageSource.AddString(L"3: 同三维采集卡");
	m_comboImageSource.SetCurSel(gSystemMgr.m_nImageSource);

	m_comboTestMode.ResetContent();
	m_comboTestMode.AddString(L"0: 原图显示");
	m_comboTestMode.AddString(L"1: SFR测试");
	m_comboTestMode.AddString(L"2: ");
	m_comboTestMode.AddString(L"3: ");
	m_comboTestMode.SetCurSel(gSystemMgr.m_nTestMode);

	m_comboCaptureMode.ResetContent();
	m_comboCaptureMode.AddString(L"0: 单张");
	m_comboCaptureMode.AddString(L"1: 连续");
	m_comboCaptureMode.SetCurSel(gSystemMgr.m_nCaptureMode);

	m_comboChangeMode.ResetContent();
	m_comboChangeMode.AddString(L"0: 原图");
	m_comboChangeMode.AddString(L"1: UYVY");
	m_comboChangeMode.AddString(L"2: VYUY");
	m_comboChangeMode.AddString(L"3: YVYU");
	m_comboChangeMode.AddString(L"4: YUYV");
	m_comboChangeMode.SetCurSel(gSystemMgr.m_nImageChangeMode);

	m_comboGpioNo.ResetContent();
	m_comboGpioNo.AddString(L"0");
	m_comboGpioNo.AddString(L"1");
	m_comboGpioNo.AddString(L"2");
	m_comboGpioNo.AddString(L"3");
	m_comboGpioNo.SetCurSel(gSystemMgr.m_nGpioNo);

	CWnd* ctrl = GetTopWindow();
	while (ctrl != NULL)
	{
		ctrl->EnableWindow(gSystemMgr.isAdmin ? TRUE : FALSE);
		ctrl = ctrl->GetNextWindow();
	}

	if (!gSystemMgr.isAdmin)
	{
		GetDlgItem(IDC_EDIT121)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_CHECKGD)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_SAVE)->EnableWindow(TRUE);
	}

	return TRUE;  
}


void CImageCaptureDlg::OnCancel()
{
	// TODO: 在此添加专用代码和/或调用基类

	CDialogEx::OnCancel();
}

void CImageCaptureDlg::ReadConfigIni()
{
	(gSystemMgr.m_bWriteIIC == 1) ? m_bWriteiic = true : m_bWriteiic = false;
	(gSystemMgr.m_bMirrorX == 1) ? m_bMirrorX = true : m_bMirrorX = false;
	(gSystemMgr.m_bMirrorY == 1) ? m_bMirrorY = true : m_bMirrorY = false;
	(gSystemMgr.m_bMirrorXt == 1) ? m_bMirrorXt = true : m_bMirrorXt = false;
	(gSystemMgr.m_bMirrorYt == 1) ? m_bMirrorYt = true : m_bMirrorYt = false;
	(gSystemMgr.m_bChangeXYFlag==1)? m_bChangeXY = true : m_bChangeXY = false;
	m_nCTSId = gSystemMgr.m_nCtsId;
	m_dFeildRatio = gSystemMgr.m_dFeildRatio;
	m_nCTSId = gSystemMgr.m_nCtsId;
	(gSystemMgr.m_bGpioFlag == 1) ? m_nGpioFlag = true : m_nGpioFlag = false;
	//gSystemMgr.m_nCaptureMode;
	//m_bChangeXY = gSystemMgr.m_bChangeXYFlag;

	FW_SlaveAdd = gSystemMgr.FW_SlaveAdd;
	SNAddr = gSystemMgr.SNAddr;
	IICFlag = gSystemMgr.IICFlag;
	m_nCenterWide = gSystemMgr.m_nCenterWide;
	m_nFeildWide = gSystemMgr.m_nFeildWide;
	IMAGE_W = gSystemMgr.IMG_W;
	IMAGE_H = gSystemMgr.IMG_H;

	isOpenMes = gSystemMgr.isOpenMes;
	MesIP = gSystemMgr.mesIP;
	MesPort = gSystemMgr.mesPort;
	wpCode = gSystemMgr.wp_code;
	gdNo = gSystemMgr.gdNo;

	UpdateData(FALSE);
}

void CImageCaptureDlg::SaveValueToConfig()
{
	CString cstr;
	gSystemLog.DisplayLogAndSave(L"Capture参数修改前：", LV_ERROR);
	cstr.Format(L"WriteIIC开启:%d", gSystemMgr.m_bWriteIIC);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"跳Gpio开启:%d", gSystemMgr.m_bGpioFlag);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"X/Y轴互换开启:%d", gSystemMgr.m_bChangeXYFlag);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"测试选项:%d", gSystemMgr.m_nTestMode);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"采图模式:%d", gSystemMgr.m_nCaptureMode);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"图片转换:%d", gSystemMgr.m_nImageChangeMode);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);

	gSystemLog.DisplayLogAndSave(L"镜像设定：", LV_ERROR);
	cstr.Format(L"MirrorX开启:%d", gSystemMgr.m_bMirrorX);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"MirrorY开启:%d", gSystemMgr.m_bMirrorY);	
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"MirrorXt开启:%d", gSystemMgr.m_bMirrorXt);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"MirrorYt开启:%d", gSystemMgr.m_bMirrorYt);	
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"IIC条码读取开启:%d", gSystemMgr.IICFlag); 
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"芯片地址:%s", gSystemMgr.FW_SlaveAdd);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"SN地址:%s", gSystemMgr.SNAddr);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);

	cstr.Format(L"像高:%.3f", gSystemMgr.m_dFeildRatio);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);

	/*cstr.Format(L"%d", gSystemMgr.m_nImageSource);	
	cstr.Format(L"%d", gSystemMgr.m_nTestMode);	
	cstr.Format(L"%d", gSystemMgr.m_nCaptureMode);	
	cstr.Format(L"%d", gSystemMgr.m_nImageChangeMode);	
	cstr.Format(L"%d", gSystemMgr.m_nCtsId);	
	cstr.Format(L"%d", gSystemMgr.m_nCenterLineType);	
	cstr.Format(L"%d", gSystemMgr.m_nFeildLineType);	
	cstr.Format(L"%d", gSystemMgr.m_nCenterLineColor);	
	cstr.Format(L"%d", gSystemMgr.m_nFeildLineColor);	
	cstr.Format(L"%d", gSystemMgr.m_nGpioNo);	
	cstr.Format(L"%d", gSystemMgr.m_bChangeXYFlag);	
	cstr.Format(L"%d", gSystemMgr.m_nCenterWide);	
	cstr.Format(L"%d", gSystemMgr.m_nFeildWide);*/
	
	

	UpdateData(TRUE);

	(m_bWriteiic == TRUE) ? gSystemMgr.m_bWriteIIC = 1 : gSystemMgr.m_bWriteIIC = 0;
	(m_bMirrorX == TRUE) ? gSystemMgr.m_bMirrorX = 1 : gSystemMgr.m_bMirrorX = 0;
	(m_bMirrorY == TRUE) ? gSystemMgr.m_bMirrorY = 1 : gSystemMgr.m_bMirrorY = 0;
	(m_bMirrorXt == TRUE) ? gSystemMgr.m_bMirrorXt = 1 : gSystemMgr.m_bMirrorXt = 0;
	(m_bMirrorYt == TRUE) ? gSystemMgr.m_bMirrorYt = 1 : gSystemMgr.m_bMirrorYt = 0;
	
	gSystemMgr.IMG_W = IMAGE_W;
	gSystemMgr.IMG_H = IMAGE_H;
	gSystemMgr.m_nImageSource = m_comboImageSource.GetCurSel();
	gSystemMgr.m_nTestMode = m_comboTestMode.GetCurSel();
	gSystemMgr.m_nCaptureMode = m_comboCaptureMode.GetCurSel();
	gSystemMgr.m_nImageChangeMode = m_comboChangeMode.GetCurSel();
	gSystemMgr.m_CenterLineType	= m_comboCenterLineType.GetCurSel();
	gSystemMgr.m_FeildLineType = m_comboFeildLineType.GetCurSel();
	gSystemMgr.m_CenterLineColor = m_comboCenterLineColor.GetCurSel();
	gSystemMgr.m_FeildLineColor = m_comboFeildLineColor.GetCurSel();
	gSystemMgr.m_nCtsId = m_nCTSId;
	gSystemMgr.m_dFeildRatio = m_dFeildRatio;
	(m_nGpioFlag == TRUE) ? gSystemMgr.m_bGpioFlag = 1 : gSystemMgr.m_bGpioFlag = 0;
	gSystemMgr.m_nGpioNo = m_comboGpioNo.GetCurSel();
	gSystemMgr.m_bChangeXYFlag = m_bChangeXY;

	gSystemMgr.FW_SlaveAdd = FW_SlaveAdd;
	gSystemMgr.SNAddr = SNAddr;
	gSystemMgr.IICFlag = IICFlag;

	gSystemMgr.isOpenMes = isOpenMes;
	gSystemMgr.mesIP = MesIP;
	gSystemMgr.mesPort = MesPort;
	gSystemMgr.wp_code = wpCode;
	gSystemMgr.gdNo = gdNo;

	//gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"FW_SlaveAdd", gSystemMgr.FW_SlaveAdd); 
	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"FW_SlaveAdd", gSystemMgr.FW_SlaveAdd);
	gSystemMgr.m_cIICCheckConfigIni.SaveConfigIni(L"IICCheck", L"SNAddr", gSystemMgr.SNAddr);
	cstr.Format(L"%d", gSystemMgr.IICFlag);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"IICFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bWriteIIC);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_bWriteIIC", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bMirrorX);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_bMirrorX", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bMirrorY);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_bMirrorY", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bMirrorXt);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_bMirrorXt", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bMirrorYt);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_bMirrorYt", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nImageSource);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nImageSource", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCtsId);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nCtsId", cstr);

	cstr.Format(L"%d", gSystemMgr.IMG_W);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"IMG_W", cstr);
	cstr.Format(L"%d", gSystemMgr.IMG_H);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"IMG_H", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nCenterLineType);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nCenterLineType", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFeildLineType);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nFeildLineType", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCenterLineColor);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nCenterLineColor", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFeildLineColor);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nFeildLineColor", cstr);
	
	cstr.Format(L"%d", gSystemMgr.m_nTestMode);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nTestMode", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bGpioFlag);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_bGpioFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nGpioNo);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nGpioNo", cstr);
	
	cstr.Format(L"%d", gSystemMgr.m_nCenterWide);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nCenterWide", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFeildWide);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nFeildWide", cstr);
	cstr.Format(L"%.3f", gSystemMgr.m_dFeildRatio);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_dFeildRatio", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bChangeXYFlag);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_bChangeXYFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCaptureMode);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nCaptureMode", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nImageChangeMode);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"m_nImageChangeMode", cstr);

	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"mesIP", gSystemMgr.mesIP);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"wp_code", gSystemMgr.wp_code);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"gdNo", gSystemMgr.gdNo);
	cstr.Format(L"%d", gSystemMgr.mesPort);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"mesPort", cstr);
	cstr.Format(L"%d", gSystemMgr.isOpenMes);
	gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"CaptureConfig", L"isOpenMes", cstr);

	switch (gSystemMgr.m_nImageSource) {
	case IMG_DEV_FILE:
		gSystemMgr.imgCap = (ImgCap *)&gSystemMgr.imgFile;
		//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"Image Files");
		break;
	case IMG_DEV_CTS:
		if (gSystemMgr.m_bCTSInitFlag == 0) {
			Cam_Init();
			gSystemMgr.m_bCTSInitFlag = 1;
		}
		gSystemMgr.imgCap = (ImgCap *)&gSystemMgr.imgCTS;
		//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"CTS Cam");
		break;
	case IMG_RO_LONGO:
		gSystemMgr.imgCap = (ImgCap *)&gSystemMgr.imgRLG;
		//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"RLG Cam");
		break;
	}

	gSystemLog.DisplayLogAndSave(L"Capture参数修改后：", LV_ERROR);
	cstr.Format(L"WriteIIC开启:%d", gSystemMgr.m_bWriteIIC);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"跳Gpio开启:%d", gSystemMgr.m_bGpioFlag);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"X/Y轴互换开启:%d", gSystemMgr.m_bChangeXYFlag);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"测试选项:%d", gSystemMgr.m_nTestMode);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"采图模式:%d", gSystemMgr.m_nCaptureMode);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"图片转换:%d", gSystemMgr.m_nImageChangeMode);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);

	gSystemLog.DisplayLogAndSave(L"镜像设定：", LV_ERROR);
	cstr.Format(L"MirrorX开启:%d", gSystemMgr.m_bMirrorX);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"MirrorY开启:%d", gSystemMgr.m_bMirrorY);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"MirrorXt开启:%d", gSystemMgr.m_bMirrorXt);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"MirrorYt开启:%d", gSystemMgr.m_bMirrorYt);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"IIC条码读取开启:%d", gSystemMgr.IICFlag);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"芯片地址:%s", gSystemMgr.FW_SlaveAdd);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"SN地址:%s", gSystemMgr.SNAddr);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	cstr.Format(L"像高:%.3f", gSystemMgr.m_dFeildRatio);
	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);

	gSystemLog.DisplayLogAndSave(L"Capture保存数据完成", LV_EVENT);
}

void CImageCaptureDlg::OnBnClickedButtonSave()
{
	SaveValueToConfig();
	//换成窗口截图
	//SYSTEMTIME st;
	//GetLocalTime(&st);
	//char file_name[MAX_PATH] = { 0 };
	//sprintf(file_name, "%s\\[%02d%02d%02d%02d%02d%02d][%s]CaptureConfig.jpg",  st.wYear,st.wMonth,st.wDay,st.wHour, st.wMinute, st.wSecond, gSystemMgr.HolderSN);
	//HWND hwnd = FindWindow("CImageCaptureDlg", NULL);
	//gSystemMgr.save_drawing_image_jpg(hwnd, file_name);
}



void CImageCaptureDlg::OnBnClickedButtonWriteiic()
{
	//gSystemMgr.imgCTS.write_iic();
	switch (gSystemMgr.m_nImageSource)
	{
	case IMG_DEV_CTS:
		gSystemMgr.imgCTS.write_iic();
		break;
	case IMG_RO_LONGO:
		gSystemMgr.imgRLG.write_iic();
		break;
	}
}


void CImageCaptureDlg::OnBnClickedButtonReadiic()
{
	gSystemMgr.imgCTS.read_iic();
	// TODO: 在此添加控件通知处理程序代码
}



void CImageCaptureDlg::OnBnClickedButtonSave2()
{
	// TODO: 在此添加控件通知处理程序代码
	//BYTE IIC_SN[25] = { 0 };
	memset(gSystemMgr.IIC_SN, 0, sizeof(gSystemMgr.IIC_SN));
	gSystemMgr.imgRLG.read_iic_check_sn();
	CString cstrLog;
	USES_CONVERSION;
	cstrLog.Format(L"%s", A2T((char*)gSystemMgr.IIC_SN));
	SetDlgItemTextW(IDC_Show_SN, cstrLog);
}

void CImageCaptureDlg::OnBnClickedButtonCheckgd()
{
	CString gd = L"";
	GetDlgItemText(IDC_EDIT121, gd);
	USES_CONVERSION;
	bool v = gSystemMgr.MesCheckGD(T2A(gd));
	if (v)
	{
		MessageBox(L"工单OK", L"校验工单");
	}
	else
	{
		MessageBox(L"工单NG", L"校验工单", MB_ICONERROR);
	}
}
